public class Solution1290 {

    public static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public int getDecimalValue(ListNode head) {
        int r=0;
        while (head!=null){
            r=r*2+head.val;
            head=head.next;
        }
        return r;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1290().getDecimalValue(new ListNode(1,new ListNode(0,new ListNode(1)))));
    }
}
